summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/uic/barcode/ssbFrame/SsbNonUic.java
blob: 1f0049e5d747e812e707db07f7d88f69abb5aa68 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package org.uic.barcode.ssbFrame;

import org.uic.barcode.asn1.uper.AsnUtils;
import org.uic.barcode.asn1.uper.BitBuffer;
import org.uic.barcode.asn1.uper.ByteBitBuffer;

public class SsbNonUic extends SsbTicketPart {
	

	
	
	byte[] openData = null;

	@Override
	protected int decodeContent(byte[] bytes, int offset) {
		
		BitBuffer bits = new ByteBitBuffer(bytes);
			
		StringBuffer sb = new StringBuffer();
		
		
		for (int i = offset; i < openDataLength; i++) {
			if (bits.get(i) == false) {
				sb.append("1");
			} else {
				sb.append("0");
			}
		}
		
		for (int i = openDataLength; i < 440; i++) {
			sb.append("0");
		}	
		
		openData = AsnUtils.fromBooleanString(sb.toString());
		
		return offset + openDataLength ;
		
	}

	@Override
	protected int encodeContent(byte[] bytes, int offset) {
		
		BitBuffer bits = new ByteBitBuffer(bytes);
		
		String bitString = AsnUtils.toBooleanString(openData);
		
	
		for (int i = 0; i< openDataLength ; i++) {
			if (i < bitString.length() && bitString.charAt(i) == '0') {
				bits.put(offset + i, true);
			} else {
				bits.put(offset + i, false);
			}
		}
		
		return offset + openDataLength;
	}

	public byte[] getOpenData() {
		return openData;
	}

	public void setOpenData(byte[] openData) {
		this.openData = openData;
	}
	
	
	
}